package com.geely.design.pattern.behavioral.memento;

public class Test {
    public static void main(String[] args) {
        ArticleMementoManager articleMementoManager = new ArticleMementoManager();

        // 新建
        Article article = new Article("Photoshop", "Photoshop CC", "Photoshop CC 2020");
        System.out.println("当前内容: " + article);

        // 转成快照
        ArticleMemento articleMemento = article.saveToMemento();

        // 将快照存档
        articleMementoManager.addMemento(articleMemento); // 把快照存到ArticleMementoManager中
        System.out.println("暂存成功：" + articleMemento);

        System.out.println("====================修改article开始====================");

        article.setTitle("Blender");
        article.setContent("blender");
        article.setImgs("blender 3d");

        System.out.println("====================修改article完毕====================");

        System.out.println("当前内容: " + article);

        System.out.println("====================从暂存中恢复====================");
        article.undoFromMemento(articleMementoManager.getMemento()); // 从ArticleMementoManager中取最近添加的

        System.out.println("恢复内容: " + article);

    }
}
